package com.streamsets.datacollector.model.jdbc;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;

/**
 * 设置JDBC数据源需要的参数
 * @author wengzhonghui
 * @date 2019/6/18 19:32
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class SourceJdbcConfigJson implements Serializable {
    // 抽取的SQL，mysql->mysql的时候有用到,mysql->hive时用不到
    String  sourceQuerySql;
    // 采集的数据库表名，如device
    String sourceTable;
    // 增量同步的初始值
    String initialOffset;
    // 增量同步对应的列
    String offsetColumn;

    // 增量同步对应的主键
    String priColumn;

    // 增量同步对应的列类型,date 或者int
    String offsetColumnType;

    // 查询的时间间隔，单位(s), 使用时需转换成：如${10 * SECONDS}
    Integer queryInterval;
    // 单批次同步的最大数量
    Integer maxBatchSize;
    //
    Integer maxClobSize;
    // 单位(s)
    Integer newTableQueryInterval;
    // 捕获数据变化的列，如 update_time
    String txnIdColumnName;
    // 数据库JDBC连接，如jdbc:mysql://172.30.0.62:3306/streamset_test
    String connectionString;
    // 数据库账号
    String jdbcUserName;
    // 数据库密码
    String jdbcPassword;
    // 驱动名称
    String driverClassName;
    //
    String connectionTestQuery;
    // 是否增量
    Integer isIncrementalMode;




    public SourceJdbcConfigJson(
            @JsonProperty("sourceQuerySql")String sourceQuerySql,
            @JsonProperty("sourceTable")String sourceTable,
            @JsonProperty("initialOffset") String initialOffset,
            @JsonProperty("offsetColumn") String offsetColumn,
            @JsonProperty("priColumn") String priColumn,
            @JsonProperty("offsetColumnType") String offsetColumnType,
            @JsonProperty("queryInterval")Integer queryInterval,
            @JsonProperty("maxBatchSize")Integer maxBatchSize,
            @JsonProperty("maxClobSize")Integer maxClobSize,
            @JsonProperty("newTableQueryInterval")Integer newTableQueryInterval,
            @JsonProperty("txnIdColumnName")String txnIdColumnName,
            @JsonProperty("connectionString")String connectionString,
            @JsonProperty("jdbcUserName")String jdbcUserName,
            @JsonProperty("jdbcPassword")String jdbcPassword,
            @JsonProperty("driverClassName")String driverClassName,
            @JsonProperty("connectionTestQuery")String connectionTestQuery,
            @JsonProperty("isIncrementalMode") Integer isIncrementalMode
            ) {

        newTableQueryInterval = newTableQueryInterval==null ? 10: newTableQueryInterval;
        maxBatchSize = maxBatchSize==null ? 1000: maxBatchSize;

        this.sourceQuerySql = sourceQuerySql;
        this.sourceTable = sourceTable;
        this.initialOffset = initialOffset;
        this.offsetColumn = offsetColumn;
        this.priColumn = priColumn;
        this.queryInterval = queryInterval;
        this.maxBatchSize = maxBatchSize;
        this.maxClobSize = maxClobSize;
        this.newTableQueryInterval = newTableQueryInterval;
        this.txnIdColumnName = txnIdColumnName;
        this.connectionString = connectionString;
        this.jdbcUserName = jdbcUserName;
        this.jdbcPassword = jdbcPassword;
        this.driverClassName = driverClassName;
        this.connectionTestQuery = connectionTestQuery;
        this.isIncrementalMode = isIncrementalMode;
        this.offsetColumnType = offsetColumnType;
    }

    public SourceJdbcConfigJson() {
    }

    public String getOffsetColumnType() {
        return offsetColumnType;
    }

    public void setOffsetColumnType(String offsetColumnType) {
        this.offsetColumnType = offsetColumnType;
    }

    public String getSourceTable() {
        return sourceTable;
    }

    public void setSourceTable(String sourceTable) {
        this.sourceTable = sourceTable;
    }

    public String getInitialOffset() {
        return initialOffset;
    }

    public void setInitialOffset(String initialOffset) {
        this.initialOffset = initialOffset;
    }

    public String getOffsetColumn() {
        return offsetColumn;
    }

    public void setOffsetColumn(String offsetColumn) {
        this.offsetColumn = offsetColumn;
    }

    public Integer getQueryInterval() {
        queryInterval = queryInterval==null ? 24*3600: queryInterval;
        return queryInterval;
    }

    public void setQueryInterval(Integer queryInterval) {
        this.queryInterval = queryInterval;
    }

    public Integer getMaxBatchSize() {
        maxBatchSize = maxBatchSize==null ? 1000: maxBatchSize;
        return maxBatchSize;
    }

    public void setMaxBatchSize(Integer maxBatchSize) {
        this.maxBatchSize = maxBatchSize;
    }

    public Integer getMaxClobSize() {
        maxClobSize = maxClobSize==null ? 1000: maxClobSize;
        return maxClobSize;
    }

    public void setMaxClobSize(Integer maxClobSize) {
        this.maxClobSize = maxClobSize;
    }

    public Integer getNewTableQueryInterval() {
        return newTableQueryInterval;
    }

    public void setNewTableQueryInterval(Integer newTableQueryInterval) {
        this.newTableQueryInterval = newTableQueryInterval;
    }

    public String getTxnIdColumnName() {
        return txnIdColumnName;
    }

    public void setTxnIdColumnName(String txnIdColumnName) {
        this.txnIdColumnName = txnIdColumnName;
    }

    public String getConnectionString() {
        return connectionString;
    }

    public void setConnectionString(String connectionString) {
        this.connectionString = connectionString;
    }

    public String getJdbcUserName() {
        return jdbcUserName;
    }

    public void setJdbcUserName(String jdbcUserName) {
        this.jdbcUserName = jdbcUserName;
    }

    public String getJdbcPassword() {
        return jdbcPassword;
    }

    public void setJdbcPassword(String jdbcPassword) {
        this.jdbcPassword = jdbcPassword;
    }

    public String getDriverClassName() {
        return driverClassName;
    }

    public void setDriverClassName(String driverClassName) {
        this.driverClassName = driverClassName;
    }

    public String getConnectionTestQuery() {
        return connectionTestQuery;
    }

    public void setConnectionTestQuery(String connectionTestQuery) {
        this.connectionTestQuery = connectionTestQuery;
    }

    public Boolean getIsIncrementalModeBoolean() {
        return this.isIncrementalMode != null && this.isIncrementalMode == 1;
    }

    public Integer getIsIncrementalMode() {
        return isIncrementalMode;
    }

    public void setIsIncrementalMode(Integer isIncrementalMode) {
        this.isIncrementalMode = isIncrementalMode;
    }

    public String getSourceQuerySql() {
        return sourceQuerySql;
    }

    public void setSourceQuerySql(String sourceQuerySql) {
        this.sourceQuerySql = sourceQuerySql;
    }

    public String getPriColumn() {
        return priColumn;
    }

    public void setPriColumn(String priColumn) {
        this.priColumn = priColumn;
    }
}
